<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
session_start();

class account extends CI_Controller {

    public function __construct() {
        parent::__construct();
        if ($this->session->userdata('logged_in_user')) {
            $this->logged_in = TRUE;
        } else {
            redirect('login/', 'refresh');
        }
        $this->load->model('Dao');
        $this->load->helper('date');
    }

    public function index($data = array()) {
        //print_r($data);

        $data ['user'] = $this->session->userdata('logged_in_user');
        $user = $data['user'];
        $data['title'] = 'Welcome to wfaces';
        $data['description'] = 'NONE';
        $data['keywords'] = 'Key, words, of, the, page';
        //$data['notifs'] = 'v_notifs';
        $data['view'] = 'v_account';
        //$data['users'] = $this->Dao->findUsers($user->id);
        $data['pass_inc'] = isset($data['pass_inc']) ? $data['pass_inc'] : "";
        $connections = "";

//        if ($this->session->userdata('connections')) {
//            $connections = $this->session->userdata('connections');
//            $data['friends'] = $this->Dao->findConnections($connections);
//        } else {
//            $data['friends'] = array();
//        }
//
//        $data['notifsNumber'] = $this->Dao->findNotifsNbr($user->id);
//        $data['connections'] = $connections;
//        echo "<pre>";
//        print_r($data);
//        echo "</pre>";
        $this->load->view('templates/template', $data);
    }

    public function deactivate() {
        $data = array('user' => $this->session->userdata('logged_in_user'));
        $user = $data['user'];
        $action = $this->input->post("action");
        $password = $this->input->post("password");
        $reason = $this->input->post("reason");


        $data = $this->input->post();
        $data['pass_inc'] = "";


        //echo "-" . $action . "&nbsp;&nbsp;&nbsp;&nbsp;" . $password . "&nbsp;&nbsp;&nbsp;&nbsp;" . $reason . "-";
        if (!$this->Dao->verifPass($user->id, $password)) {
            $data['pass_inc'] = "pass_inc";
            $this->index($data);
        } else {
            if ($action == "D") {
                $this->Dao->DisableAccount($user->id, $reason);
                redirect("login/logout", "refresh");
            }
            if ($action == "S") {
                if ($this->Dao->DeleteAccount($user->id, $reason)) {
                    redirect("login/logout", "refresh");
                }
            }
        }
    }

    public function status() {
        $new_status = $this->input->post("status");
       // $new_status = $new_status == "1" ? "a-online" : "c-offline";
        echo $this->Dao->forceStatus($new_status);
    }

}

?>
